package cn.itcast.web.action;

import cn.itcast.domain.delivery.Order;
import cn.itcast.service.OrderService;
import cn.itcast.utils.ResponseUtils;
import cn.itcast.web.action.common.BaseAction;
import com.alibaba.fastjson.JSONArray;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Actions;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import java.util.HashMap;
import java.util.Map;

@Namespace("/")
@ParentPackage("struts-default")
@Controller
@Scope("prototype")
@Actions
public class OrderAction extends BaseAction<Order> {
    @Autowired
    private OrderService orderService;

    //$.post("../../order_findOrderByNum.action"
    @Action(value = "order_findOrderByNum")
    public String findOrderByNum() {
        Map<String, Object> result = new HashMap<String, Object>();//数据封装处理
        Order order = orderService.findOrderByNum(model.getOrderNum());
        if(order==null){
            //运单不存在
            result.put("success",false);
        }else {
            //封装数据 进行回显
            result.put("success",true);
            result.put("orderData",order);
        }
        //响应数据
        String data = JSONArray.toJSONString(result);
        ResponseUtils.responseWriter(data);
        return NONE;
    }

}
